/*   1:    */ package org.intellij.images.ui;
/*   2:    */ 
/*   3:    */

import com.intellij.util.ui.UIUtil;
import org.intellij.images.editor.ImageDocument;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.image.BufferedImage;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */ 
/*  15:    */ public class ImageComponentUI
/*  16:    */   extends ComponentUI
/*  17:    */ {
/*  18: 35 */   private static final ImageComponentUI a = new ImageComponentUI();
/*  19:    */   
/*  20:    */   public void paint(Graphics paramGraphics, JComponent paramJComponent)
/*  21:    */   {
/*  22: 38 */     ImageComponent localImageComponent = (ImageComponent)paramJComponent;
/*  23: 39 */     if (localImageComponent != null)
/*  24:    */     {
/*  25: 40 */       ImageDocument localImageDocument = localImageComponent.getDocument();
/*  26: 41 */       BufferedImage localBufferedImage = localImageDocument.getValue();
/*  27: 42 */       if (localBufferedImage != null)
/*  28:    */       {
/*  29: 43 */         a(paramGraphics, localImageComponent);
/*  30:    */         
/*  31: 45 */         Dimension localDimension = localImageComponent.getCanvasSize();
/*  32: 46 */         Graphics localGraphics = paramGraphics.create(2, 2, localDimension.width, localDimension.height);
/*  33: 49 */         if (localImageComponent.isTransparencyChessboardVisible()) {
/*  34: 50 */           b(localGraphics, localImageComponent);
/*  35:    */         }
/*  36: 53 */         c(localGraphics, localImageComponent);
/*  37: 56 */         if (localImageComponent.isGridVisible()) {
/*  38: 57 */           d(localGraphics, localImageComponent);
/*  39:    */         }
/*  40: 60 */         localGraphics.dispose();
/*  41:    */       }
/*  42:    */     }
/*  43:    */   }
/*  44:    */   
/*  45:    */   private void a(Graphics paramGraphics, ImageComponent paramImageComponent)
/*  46:    */   {
/*  47: 66 */     Dimension localDimension = paramImageComponent.getSize();
/*  48: 67 */     paramGraphics.setColor(paramImageComponent.getTransparencyChessboardBlackColor());
/*  49: 68 */     paramGraphics.drawRect(0, 0, localDimension.width - 1, localDimension.height - 1);
/*  50:    */   }
/*  51:    */   
/*  52:    */   private void b(Graphics paramGraphics, ImageComponent paramImageComponent)
/*  53:    */   {
/*  54: 72 */     Dimension localDimension = paramImageComponent.getCanvasSize();
/*  55:    */     
/*  56: 74 */     int i = paramImageComponent.getTransparencyChessboardCellSize();
/*  57: 75 */     int j = 2 * i;
/*  58: 76 */     BufferedImage localBufferedImage = UIUtil.createImage(j, j, 2);
/*  59: 77 */     Graphics localGraphics = localBufferedImage.getGraphics();
/*  60: 78 */     localGraphics.setColor(paramImageComponent.getTransparencyChessboardWhiteColor());
/*  61: 79 */     localGraphics.fillRect(0, 0, j, j);
/*  62: 80 */     localGraphics.setColor(paramImageComponent.getTransparencyChessboardBlackColor());
/*  63: 81 */     localGraphics.fillRect(0, i, i, i);
/*  64: 82 */     localGraphics.fillRect(i, 0, i, i);
/*  65:    */     
/*  66: 84 */     ((Graphics2D)paramGraphics).setPaint(new TexturePaint(localBufferedImage, new Rectangle(0, 0, j, j)));
/*  67: 85 */     paramGraphics.fillRect(0, 0, localDimension.width, localDimension.height);
/*  68:    */   }
/*  69:    */   
/*  70:    */   private void c(Graphics paramGraphics, ImageComponent paramImageComponent)
/*  71:    */   {
/*  72: 89 */     ImageDocument localImageDocument = paramImageComponent.getDocument();
/*  73: 90 */     Dimension localDimension = paramImageComponent.getCanvasSize();
/*  74:    */     
/*  75: 92 */     Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
/*  76: 93 */     RenderingHints localRenderingHints = localGraphics2D.getRenderingHints();
/*  77:    */     
/*  78:    */ 
/*  79: 96 */     localGraphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
/*  80: 97 */     localGraphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
/*  81: 98 */     paramGraphics.drawImage(localImageDocument.getRenderer(), 0, 0, localDimension.width, localDimension.height, paramImageComponent);
/*  82:    */     
/*  83:100 */     localGraphics2D.setRenderingHints(localRenderingHints);
/*  84:    */   }
/*  85:    */   
/*  86:    */   private void d(Graphics paramGraphics, ImageComponent paramImageComponent)
/*  87:    */   {
/*  88:104 */     Dimension localDimension = paramImageComponent.getCanvasSize();
/*  89:105 */     BufferedImage localBufferedImage = paramImageComponent.getDocument().getValue();
/*  90:106 */     int i = localBufferedImage.getWidth();
/*  91:107 */     int j = localBufferedImage.getHeight();
/*  92:108 */     double d1 = localDimension.width / i;
/*  93:109 */     double d2 = localDimension.height / j;
/*  94:110 */     double d3 = (d1 + d2) / 2.0D;
/*  95:111 */     if (d3 >= paramImageComponent.getGridLineZoomFactor())
/*  96:    */     {
/*  97:112 */       paramGraphics.setColor(paramImageComponent.getGridLineColor());
/*  98:113 */       int k = paramImageComponent.getGridLineSpan();
/*  99:114 */       for (int m = k; m < i; m += k) {
/* 100:115 */         UIUtil.drawLine(paramGraphics, (int)(m * d1), 0, (int)(m * d1), localDimension.height);
/* 101:    */       }
/* 102:117 */       for (m = k; m < j; m += k) {
/* 103:118 */         UIUtil.drawLine(paramGraphics, 0, (int)(m * d2), localDimension.width, (int)(m * d2));
/* 104:    */       }
/* 105:    */     }
/* 106:    */   }
/* 107:    */   
/* 108:    */   public static ComponentUI createUI(JComponent paramJComponent)
/* 109:    */   {
/* 110:125 */     return a;
/* 111:    */   }
/* 112:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.ui.ImageComponentUI

 * JD-Core Version:    0.7.0.1

 */